﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Entity;
using DAL.Persistencia;

namespace DAL.Persistencia
{
    public class RoomingListDAL
    {

        private NewTierraEntities Con;

        public RoomingListDAL()
        {
            Con = new NewTierraEntities();
        }

        public void Salvar(RoomingList r)
        {
            try
            {
                Con.AddToRoomingList(r);
                Con.SaveChanges();
            }
            catch 
            {                
                throw;
            }
        }

        public RoomingList ObterPorQuote(int IdQuot)
        {
            try
            {
                return Con.RoomingList.Where(r => r.Quotation_Grupo_Id == IdQuot).FirstOrDefault();
            }
            catch 
            {                
                throw;
            }
        }

        public RoomingList ObterPorId(int IdRooming)
        {
            try
            {
                return Con.RoomingList.Where(r => r.rooming_id == IdRooming).FirstOrDefault();
            }
            catch 
            {                
                throw;
            }
        }

        public void Atualizar(RoomingList novo)
        {
            try
            {
                RoomingList antigo = ObterPorId(novo.rooming_id);

                antigo.rooming_text = novo.rooming_text;

                Con.SaveChanges();

            }
            catch 
            {                
                throw;
            }
        }

    }
}
